package org.example.config;

import com.baomidou.mybatisplus.core.enums.SqlMethod;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * @Title : RepayPlanUpdateByIdAndOther
 * @Description:
 * @author: libo@juzishuke.com
 * @date: 2023/12/18 17:02
 * @Version:1.0
 */
public class RepayPlanUpdateByIdAndOtherpayBatch extends AbstractMethod {

    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass,
            TableInfo tableInfo) {
        String sqlSrc = "<script>\\nUPDATE %s %s WHERE %s=#{%s}  %s\\n</script>";
        final String additional = optlockVersion(tableInfo) + tableInfo.getLogicDeleteSql(true, true);
        String sql = String.format(sqlSrc, tableInfo.getTableName(),
                sqlSet(tableInfo.isWithLogicDelete(), false, tableInfo, false, ENTITY, ENTITY_DOT),
                tableInfo.getKeyColumn(), ENTITY_DOT + tableInfo.getKeyProperty(), additional);
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
        return addUpdateMappedStatement(mapperClass, modelClass, "updateByIdAndOtherpayBatch", sqlSource);
    }
}
